#include "Game.h"


// methods
Boards getBoards()
{
	return myCheckers;
}

// melakukan pembacaan file bitmap
GLuint loadBMP(const char * filename)
{
	AUX_RGBImageRec *TextureImage;
	GLuint tempbmp;
	// membuka file bitmap
	FILE * bmpfile = fopen(filename, "r");
	if (!bmpfile)
	{
		cout<<"Image tidak bisa dibuka"<<endl;
	}
	else if (bmpfile)
	{
		fclose(bmpfile);
		// cout<<"keclose"<<endl;
		memset(TextureImage,0,sizeof(void *)*1);
		TextureImage = auxDIBImageLoad(filename);
		// cout<<"keload"<<endl;
		glGenTextures(1, &tempbmp);			// Create the texture
		// cout<<"kegen"<<endl;
		glBindTexture(GL_TEXTURE_2D, tempbmp);
		// cout<<"kebind"<<endl;
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
		// cout<<"kebentuk"<<endl;
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		// cout<<"keparametri"<<endl;
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		// cout<<"keparametri"<<endl;
		// cek apakah texture image eksis
		if (TextureImage)
		{
			if (TextureImage->data)
			{
				free(TextureImage->data);
			}

			free(TextureImage);
		}
		// cout<<"keload"<<endl;
		return tempbmp;
	}

	return 0;
}

void initGL()
{
	// std::cout<<"masuk"<<endl;
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glEnable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, 1.0, 0.1, 100.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearColor(0.7f, 0.9f, 1.0f, 1.0f);
}

// load the image from folder "images", and returns the id of the texture
void loadContent()
{
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_TEXTURE_2D);

	// backgroundStartMenu_id = loadBMP("images/startmenu.bmp");
	// if (themeState == classic)
	// {
		// backgroundOptions_id = loadBMP("images/klasik/options.bmp");
		// // cout<<"load1?"<<endl;
		// backgroundHelp_id = loadBMP("images/klasik/help.bmp");
		// // cout<<"load2?"<<endl;
		// backgroundCredits_id = loadBMP("images/klasik/credits.bmp");

		// // load content for gameplay
		// // cout<<"load3?"<<endl;
		// papanselected_id = loadBMP("images/klasik/papan_klasik_selected.bmp");
		// // cout<<"load4?"<<endl;
		// posibilitas_id = loadBMP("images/klasik/possibilities.bmp");
		// // cout<<"load5?"<<endl;
		// bidak1_id = loadBMP("images/klasik/bidak1.bmp");
		// // cout<<"load6?"<<endl;
		// bidak2_id = loadBMP("images/klasik/bidak2.bmp");
		// // cout<<"load7?"<<endl;
		// backgroundGamePlay_id = loadBMP("images/klasik/gameplay.bmp");
		// //backgroundHighScore_id = loadBMP(stringtemphighscore);
		// // cout<<"load6?"<<endl;
		// bidak1_id_pressed = loadBMP("images/klasik/bidak1_pressed.bmp");
		// // cout<<"load7?"<<endl;
		// bidak2_id_pressed = loadBMP("images/klasik/bidak2_pressed.bmp");
		// // cout<<"load8?"<<endl;
	// }
	// else if (themeState == unyu)
	// {
		// backgroundOptions_id = loadBMP("images/unyu/options.bmp");
		// backgroundHelp_id = loadBMP("images/unyu/help.bmp");
		// backgroundCredits_id = loadBMP("images/unyu/credits.bmp");
		// papan_id = loadBMP("images/unyu/boardunyu.bmp");
		// // cout<<"image papan keload?"<<endl;
		// papanselected_id = loadBMP("images/unyu/board_unyu_selected.bmp");
		// posibilitas_id = loadBMP("images/unyu/possibilities.bmp");
		// bidak1_id = loadBMP("images/unyu/bidak1.bmp");
		// bidak2_id = loadBMP("images/unyu/bidak2.bmp");
		// backgroundGamePlay_id = loadBMP("images/unyu/boardunyu.bmp");
		// //backgroundHighScore_id = loadBMP(stringtemphighscore);
	// }
}

void initialize()
{
	// region kerjaan mp
	// init state
	// gameState = highscore;
	themeState = classic;
    inputState = player1;
	selectPlayerState = pvp;
	speedMode = low;
	greedyChoiceCom1 = one;
	greedyChoiceCom2 = one;
	boardSizeMode = eight;
	player1name = " ";
	player2name = " ";
	bool flag;
	length = 0;
	length1 = 0;
	length2 = 0;
	// endregion kerjaan mp

	initGL();
	//loadContent();
	initGame = false;
	// endGame = false;
	// gameStatus = playing;
	int gameLoad;
	mHistory.LoadLastGameStatus(&flag, statusFile, &gameLoad);
	cout<<endl<<"game di load = "<<gameLoad;
	// if (gameLoad==3){
		// gameStatus = playing;
	// }
	// else{
		// gameStatus = gameLoad;
	// }
	cout<<endl<<"game di load = "<<gameStatus;
	if (!flag){
		gameStatus == playing;
	}
	else{
		gameStatus = gameLoad;
	}
	cout<<endl<<"game di load = "<<gameStatus;
}
double diffclock(clock_t clock1,clock_t clock2)
{
	double diffticks=clock1-clock2;
	double diffms=(diffticks*100)/CLOCKS_PER_SEC;
	return diffms;
}
void clearPossibleArea(){
	possibleAreaToMove[0][0] = 0;
	possibleAreaToMove[0][1] = 0;
	possibleAreaToMove[0][2] = 0;
	possibleAreaToMove[0][3] = 0;
	possibleAreaToMove[0][4] = 0;
}

float widthRatio(int width, int gameWidth)
{
	return (float) width / gameWidth;
}

float heightRatio(int height, int gameHeight)
{
	return (float) height / gameHeight;
}

// region kerjaan mp
void keyPressed(unsigned char key, int x, int y)
{
	if (key == 27) // jika tombol escape ditekan
	{
		if (gameState == gameplay){
			if (gameStatus==playing){
				gameStatus = stop_game;
			}
			mHistory.SaveLastGameStatus(statusFile, gameStatus);
			mHistory.SaveLastGame(gameFile, myCheckers.allCoin(), boardSize, battleMode, comLevel, turn, enemyFront, player1name, player2name, (int)begin);
			gameState = startmenu;
			initialize();
		}
		else if (gameState == startmenu){
			exit(0); // jika tombol escape ditekan
		}
		else{
			gameState = startmenu;
		}
	}
	else if (key == 8) // jika tombol backspace ditekan
	{
		if (gameState == gameplay){
				// string name = player1name;
				// int coin = myCheckers.remainingCoin(1);
				// int time = (int)diffclock(end,begin);
				// mHistory.inputPlayer(name, coin, time);
				// mHistory.SaveHighScore(scoreFile, name, coin, time);

			gameState = options;
		}
		else if (gameState == options){
			if  (length >= 0)
			{
				--length;
				if (inputState == player1)
				{
					player1name[length] = ' ';
					length1 = length;
				}
				else if (inputState == player2)
				{
					player2name[length] = ' ';
					length2 = length;
				}
			}
			else
			{
				length = 0;
				// case GLUT_KEY_F4 : 			
					// mHistory.SaveLastGame(saveFile, myCheckers.allCoin(), boardSize, battleMode, comLevel, turn, enemyFront);

				// break;
			}
		}
	}
	else
	{
		if(length < 10)
		{
			if (inputState == player1)
			{
				player1name[length] = (char)key;
				length1 = length + 1;
			}
			else if (inputState == player2)
			{
				player2name[length] = (char)key;
				length2 = length + 1;
			}

			++length;
		}
		else
		{
        	length = 10;
		}
	}
}

void mouseButton(int button, int state, int x, int y)
{
	int selectTheCoin;
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		std::cout<<endl<<"x ="<<x<<",y ="<<y;
		if (gameState == startmenu)
		{
			//gameState = gameplay;
		   // jika tombol main baru ditekan
		   if ((278 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (553 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (403 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (450 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
		   {
				gameState = options;
				// gameStatus = playing;


				// newCheckers();
				// gameState = gameplay;
		   }
			   // jika tombol lanjutkan ditekan
		   if (((75 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (244 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (555 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (620 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))) || ((244 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (382 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (536 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (586 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))))
		   {                                                                                                                                                                                                                                                                                                                                                                                                                           l
				if (gameStatus == stop_game){
					//loadData();
					//gameStatus = playing;
					gameState = gameplay;
				}
		   }

		   // jika tombol nilai tertinggi ditekan
		   if (((506 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (584 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (501 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (552 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))) || ((584 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (663 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (483 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (537 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))) || ((663 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (756 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (473 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (523 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))) || ((756 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (823 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (464 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (517 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))) || ((823 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (842 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) && (483 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (509 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0))))
		   {
				gameState = highscore;
		   }

		   // jika tombol keluar ditekan
		   if ((821 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1115 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (39 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (103 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
		   {
           		exit(0);
		   }
		}
		else if (gameState == gameplay){
			if (gameStatus==playing){
				int moveTo=0;
			   if ((105 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (205 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (475 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (525* (glutGet(GLUT_WINDOW_HEIGHT)/768.0))){
					if (themeState == classic){
						themeState = unyu;
					}
					else{
						themeState = classic;
					}
			   }
				else if ((turn ==1)||(turn ==2)){			
					if ((myCheckers.isForceEnemy(turn)) && (!enemyFront)){ // jika harus memakan lawan dan baru pertama kali
						enemyFront = true; // penanda bahwa harus memakan lawan
						//cout<<endl<<"harus makan!!!";
					}
					if ((myCheckers.stillForceEnemy(currentCoin)) && (((currentTurn('r') && (myCheckers.getType(currentCoin)==1))) || ((currentTurn('b') && (myCheckers.getType(currentCoin)==2))))){ // jika sudah tidak bisa memakan lawan lagi
						selectTheCoin = 0;
					}
					else{
						selectTheCoin = getCoinFromMouse(x, y);
					}					
					if ((selectTheCoin>0) && (selectTheCoin<=(myCheckers.coinMaxIdx+1))){
						coinSelected = selectTheCoin;					
						clearPossibleArea();						
						fillPossibleArea(coinSelected);
					}
					else{
						if (possibleAreaToMove[0][0]!=0){
							if (enemyFront){
								int killChance = onDirectionKill(coinSelected, getAreaFromMouse(x,y)[0], getAreaFromMouse(x,y)[1]);
								// std::cout<<endl<<"kill chance = "<<killChance;
								if (killChance!=0){
									if ((possibleAreaToMove[0][killChance]==2) && (myCheckers.isPassAble(coinSelected, killChance))){
										moveTo = killChance;
									}
								}
								
							}
							else{
								int moveChance = onDirectionMove(coinSelected, getAreaFromMouse(x,y)[0], getAreaFromMouse(x,y)[1]);
								std::cout<<endl<<"move chance = "<<moveChance;
								if (moveChance!=0){
									if ((possibleAreaToMove[0][moveChance]==1) && (myCheckers.ableToMove(coinSelected, moveChance))){
										moveTo = moveChance;
									}
								}
							}
							if (moveTo!=0){							
								if (enemyFront){ // jika ada lawan
									lastMove[0] = myCheckers.getCoin(coinSelected).getX();
									lastMove[1] = myCheckers.getCoin(coinSelected).getY();
									int statusBidak = myCheckers.getCoin(coinSelected).getStatus();
									myCheckers.passCoinTo(coinSelected, moveTo);
									currentCoin = coinSelected;
									if ((myCheckers.stillForceEnemy(coinSelected)) && (statusBidak==myCheckers.getCoin(currentCoin).getStatus())){ // jika sudah tidak bisa memakan lawan lagi
										//cout<<endl<<"harus makan lagi WOIII ga ganti TURN!!!";
										clearPossibleArea();
										fillPossibleArea(currentCoin);
									}
									else{
										playerTurn(); // ganti pemain
										enemyFront = false; // penanda dimatikan agar tidak memakan lawan lagi
										clearPossibleArea();
									}
								}
								else{ // jika tidak berhadapan dengan lawan
									lastMove[0] = myCheckers.getCoin(coinSelected).getX();
									lastMove[1] = myCheckers.getCoin(coinSelected).getY();
									myCheckers.moveCoinTo(coinSelected, moveTo);
									currentCoin = coinSelected;
									playerTurn(); // ganti pemain
									clearPossibleArea();
								}
//								std::cout<<endl<<"last move = "<<lastMove;
								moveTo = 0;
							}
							else{
								if ((!enemyFront)&&(selectTheCoin==0)){
									clearPossibleArea();
								}
							
							}
							
						}
						else{
							clearPossibleArea();
						}
					}					

					
				}
			}
			else{
				std::cout<<endl<<"game sudah berakhir";
			}
		}
		else if (gameState == options)
		{
			// region kerjaan mp
			if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (66 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (260 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = options;
			}
			else if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (265 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (459 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = help;
			}
			else if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (461 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (655 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = credits;
			}

			if ((247 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (763 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && gameState == options)
			{
				// jika yang diklik adalah label P1
				if ((82 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (131 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					inputState = player1;
					length = length1;
				}
				// jika yang diklik adalah label P2
				else if ((157 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (206 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					 inputState = player2;
					 length = length2;
				}
			}

			// radio button
			if ((245 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (368 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (249 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (316 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				selectPlayerState = pvp;
			}
			else if ((429 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (564 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (249 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (316 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				selectPlayerState = pvc;
			}
			else if ((618 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (763 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (259 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (301 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				selectPlayerState = cvc;
			}

			// "merubah" bg options
			if (selectPlayerState == cvc)
			{
                 // memilih greedyMode untuk COM 1
				if ((233 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (367 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (359 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (400 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom1 = one;
				}
				else if ((424 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (560 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (359 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (400 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom1 = two;
				}
				else if ((614 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (743  * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (359 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (400 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom1 = three;
				}

				// memilih greedyMode untuk COM 2
				if ((233 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (367 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (435 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (479 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom2 = one;
				}
				else if ((424 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (560 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (435 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (479 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom2 = two;
				}
				else if ((614 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (743 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (435 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (479 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					greedyChoiceCom2 = three;
				}

				 // radio button for speed mpde
				if ((241 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (368 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (504 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (553 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = low;
				}
				else if ((433 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (560 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (504 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (553 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = medium;
				}
				else if ((641 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (734 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (504 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (553 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = high;
				}

				// radio button for choosing board size
				if ((267 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (338 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (589 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (616 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					boardSizeMode = eight;
				}
				else if ((441 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (539 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (589 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (616 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					boardSizeMode = ten;
				}

				// jika tombol main ditekan
				if ((675 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (965 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (674 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (760 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					gameState = gameplay;
				}
			}
			else
			{
				// radio button
				if ((245 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (368 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (365 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (410 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = low;
				}
				else if ((429 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (564 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (365 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (410 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = medium;
				}
				else if ((618 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (763 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (365 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (410 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					speedMode = high;
				}

				// radio button
				if ((245 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (368 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (470 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (520 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))//545<= y && y <= 600)
				{
					boardSizeMode = eight;
				}
				else if ((429 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (564 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (47 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (520 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))//&& 545 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (600)
				{
					boardSizeMode = ten;
				}

				// jika tombol Main diklik
				if ((360 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (651 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (630 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (717 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
				{
					newCheckers();
					gameState = gameplay;
				}
			}
		}
		else if (gameState == help)
		{
			if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (66 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (260 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = options;
			}
			else if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (461 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (655 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = credits;
			}
		}
		else if (gameState == credits)
		{
			if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (66 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (260 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = options;
			}
			else if ((970 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) <= x && x <= (1024 * (glutGet(GLUT_WINDOW_WIDTH)/1024.0)) && (265 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)) <= y && y <= (459 * (glutGet(GLUT_WINDOW_HEIGHT)/768.0)))
			{
				gameState = help;
			}
		}

		// endregion kerjaan mp
	}

	glutPostRedisplay();
	draw();
	if (currentCoin!=0){
		// myCheckers.printCoin();
		// myCheckers.furthestCoinToKill(turn);
		// myCheckers.moveMostKill(currentCoin);
		// myCheckers.howStrongToKill(currentCoin);
		// myCheckers.coinMostKill(turn);
		// std::cout<<endl<<myCheckers.furthestCoinToMove(1);
		//std::cout<<endl<<"how strong = "<<myCheckers.howStrongToKill(3);;
	}
}
// endregion kerjaan mp
void fillPossibleArea(int coin){
	if (enemyFront){ // jika sedang berhadapan dengan lawan
		if (myCheckers.isPassAble(coin)){ // jika bidak yang dipilih adalah bidak yang tepat
			//currentCoin = coinSelected;
			possibleAreaToMove[0][0]=coin;
			if (myCheckers.isPassAble(coin, 1)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 1";
				possibleAreaToMove[0][1]=2;
			}
			if (myCheckers.isPassAble(coin, 2)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 2";
				possibleAreaToMove[0][2]=2;
			}
			if (myCheckers.isPassAble(coin, 3)){				
				//std::cout<<endl<<"ada coin ="<<coinSelected<<"yang terseleksi dan bisa melangkah ke 3";
				possibleAreaToMove[0][3]=2;
			}
			if (myCheckers.isPassAble(coin, 4)){				
				//std::cout<<endl<<"ada coin = "<<coinSelected<<" yang terseleksi dan bisa melangkah ke 4";
				possibleAreaToMove[0][4]=2;
			}
		}
	}
	else{ // jika sedang tidak berhadapan dengan lawan
		if (myCheckers.ableToMove(coin)){ // jika bidak yang dipilih adalah bidak yang tepat
			// currentCoin = coinSelected;
			possibleAreaToMove[0][0]=coin;
			if (myCheckers.ableToMove(coin, 1)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 1";
				possibleAreaToMove[0][1]=1;
			}
			if (myCheckers.ableToMove(coin, 2)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 2";
				possibleAreaToMove[0][2]=1;
			}
			if (myCheckers.ableToMove(coin, 3)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 3";
				possibleAreaToMove[0][3]=1;
			}
			if (myCheckers.ableToMove(coin, 4)){				
				// std::cout<<endl<<"ada coin yang terseleksi dan bisa melangkah ke 4";
				possibleAreaToMove[0][4]=1;
			}
		}
	}
}
int onDirectionMove(int coin, int posx, int posy){
	int result = 0;
		if (((myCheckers.getCoin(coin).getX()-posx)==1)  && ((myCheckers.getCoin(coin).getY()-posy)==1)){
			result = 1;
		// std::cout<<endl<<"Direksi 1 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==(-1))  && ((myCheckers.getCoin(coin).getY()-posy)==1)){
			result = 2;
		// std::cout<<endl<<"Direksi 2 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==(-1))  && ((myCheckers.getCoin(coin).getY()-posy)==(-1))){
			result = 3;
		// std::cout<<endl<<"Direksi 3 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==1)  && ((myCheckers.getCoin(coin).getY()-posy)==(-1))){
		// std::cout<<endl<<"Direksi 4 berhasil";
			result = 4;
		}
	std::cout<<endl<<"hasil result move = "<<result;
	return result;
}
int onDirectionKill(int coin, int posx, int posy){
		int result = 0;
		if (((myCheckers.getCoin(coin).getX()-posx)==2)  && ((myCheckers.getCoin(coin).getY()-posy)==2)){
			result = 1;
		// std::cout<<endl<<"Direksi 1 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==(-2))  && ((myCheckers.getCoin(coin).getY()-posy)==2)){
			result = 2;
		// std::cout<<endl<<"Direksi 2 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==(-2))  && ((myCheckers.getCoin(coin).getY()-posy)==(-2))){
			result = 3;
		// std::cout<<endl<<"Direksi 3 berhasil";
		}
		else if (((myCheckers.getCoin(coin).getX()-posx)==2)  && ((myCheckers.getCoin(coin).getY()-posy)==(-2))){
		// std::cout<<endl<<"Direksi 4 berhasil";
			result = 4;
		}
	return result;
}
void updateGamePlay(void)
{
	updateBoards();
	checkersRules();
}
void updateBoards(){
//	std::cout<<"boards"<<endl;

}
void checkersRules(){
	glutPostRedisplay();
	//std::cout<<"checkers"<<endl;
	if (gameState == startmenu){
	}
	else if (gameState == gameplay){
		if (gameStatus == stop_game){
				int confirmLoad;
				int modeLoad;
				int timeBegin;
				int sizeLoad;			
				int levelLoad;			
				int turnLoad;			
				bool enemyLoad;			
				bool flag;
				Coin* mCoin;
				mHistory.LoadLastGame(&flag, gameFile, mCoin, &sizeLoad, &modeLoad, &levelLoad, &turnLoad, &enemyLoad, &player1name, &player2name, &timeBegin);		
				begin = timeBegin;
				// flag = false;
				if (flag){
					boardSize = sizeLoad;
					// cout<<endl<<"berhasil load last game";
					comLevel = levelLoad;
					turn = turnLoad;
					battleMode = modeLoad;
					enemyFront = enemyLoad;
					myCheckers.initBoards(boardSize);
					cout<<endl<<"game telah di load, sizeload = "<<sizeLoad;
					cout<<endl<<"game telah di load, board = "<<boardSize;
					myCheckers.setCoin(mCoin);
					
					//myCheckers.printCoin();
					// cout<<endl<<myCheckers.getCoin(5).getX();
					// cout<<endl<<"berhasil load last game";
					// cout<<endl<<"coin Area = ";
					// for (int z=0;z<=23;z++){
						// cout<<endl<<myCoin[z].getAlive();			
					// }
				}
				else{
					// cout<<endl<<"tidak ada last game saved";
					// newCheckers();
					gameState = options;
					// cout<<endl<<"balik ke option";
				}
				gameStatus = playing;
				cout<<endl<<"game telah di load";
		}
		else if (gameStatus == playing){
			if (!initGame){
				// comLevel = 1;
				// init game
				
				//masih kasar
				// boardSize = 8;
				std::cout<<endl<<"init area";

				lastMove[0] = 0;
				lastMove[1] = 0;
				currentCoin = 0; // 0 artinya tidak
				coinSelected = 0; // 0 artinya tidak
				clearPossibleArea();
				
				// cout<<endl<<"continue game ? (1/0) = ";
				// cin>>confirmLoad;
				// if (confirmLoad==1){
				
				// flag = false;
				if (boardSize==8){
					bg_gameplay_1 = loadBMP("images/klasik/gameplay.bmp");
					bg_gameplay_2 = loadBMP("images/unyu/gameplay.bmp");
				}
				else{
					bg_gameplay_1 = loadBMP("images/klasik/gameplay_10.bmp");
					bg_gameplay_2 = loadBMP("images/unyu/gameplay_10.bmp");

				}
				// myCheckers.initArea();
				std::cout<<endl<<"fill area";
				myCheckers.fillArea();
				std::cout<<endl<<"fill area berhasil";
				initGame = true;
				begin=clock();
			}
			else{
				// waktu dimulai
				
				int moveTo=0;
				if ((turn ==3)||(turn ==4)){			
					if ((myCheckers.isForceEnemy(turn)) && (!enemyFront)){ // jika harus memakan lawan dan baru pertama kali
						enemyFront = true; // penanda bahwa harus memakan lawan
//						currentCoin = 9999; // penanda bahwa baru pertama kali harus memakan lawan
						//cout<<endl<<"harus makan!!!";
					}
					if ((myCheckers.stillForceEnemy(currentCoin)) && (((currentTurn('r') && (myCheckers.getType(currentCoin)==1))) || ((currentTurn('b') && (myCheckers.getType(currentCoin)==2))))){ // jika sudah tidak bisa memakan lawan lagi
					
						comAIMovement(&moveTo, true);
					}
					comAIMovement(&moveTo, false);
					
					if (enemyFront){
						lastMove[0] = myCheckers.getCoin(currentCoin).getX();
						lastMove[1] = myCheckers.getCoin(currentCoin).getY();
						int statusBidak = myCheckers.getCoin(currentCoin).getStatus();
						myCheckers.passCoinTo(currentCoin, moveTo);
						// lastMove[0] = myCheckers.getCoin(currentCoin).getX();
						// lastMove[1] = myCheckers.getCoin(currentCoin).getY();
						//lastMove = moveTo+4;
						if ((myCheckers.stillForceEnemy(currentCoin)) && (statusBidak==myCheckers.getCoin(currentCoin).getStatus())){ // jika sudah tidak bisa memakan lawan lagi
							// cout<<endl<<"bunuh lagi";
						}
						else{
							playerTurn(); // ganti pemain
							enemyFront = false; // penanda dimatikan agar tidak memakan lawan lagi
						}
					}
					else{
						lastMove[0] = myCheckers.getCoin(currentCoin).getX();
						lastMove[1] = myCheckers.getCoin(currentCoin).getY();
						myCheckers.moveCoinTo(currentCoin, moveTo);
//						lastMove = moveTo;
						playerTurn(); // ganti pemain
					}
				}
			
			//moveCoin();		
			}
			if ((myCheckers.remainingCoin(1)==0) || (myCheckers.noCoinCanMove(1))){ // bidak red
				end=clock();
				cout << endl<<"Time elapsed: " << double(diffclock(end,begin)) << " ms"<< endl;
				// cout << endl<<"nane = : " << name<< endl;
				// cout << endl<<"coin = : " << coin<< endl;
				// cout << endl<<"waktu double: " << double(diffclock(end,begin)) << " ms"<< endl;
				// cout << endl<<"time: " << time/100 << " ms"<< endl;
				string name = player1name;
				int coin = myCheckers.remainingCoin(1);
				int time = (int)diffclock(end,begin);
				mHistory.inputPlayer(name, coin, time);
				mHistory.SaveHighScore(scoreFile, name, coin, time);
				gameStatus = black_win;
			}
			else if ((myCheckers.remainingCoin(2)==0) || (myCheckers.noCoinCanMove(2))){ // bidak black
				end=clock();
				cout << endl<<"Time elapsed: " << double(diffclock(end,begin)) << " ms"<< endl;
				string name = player2name;
				int coin = myCheckers.remainingCoin(2);
				int time = (int)diffclock(end,begin);
				mHistory.inputPlayer(name, coin, time);
				mHistory.SaveHighScore(scoreFile, name, coin, time);

				gameStatus = red_win;
			}
			
		}
		else {
			
		}
	}
}
void newCheckers(){
	if (boardSizeMode == eight){
	boardSize = 8;
	
	}
	else{
	boardSize = 10;
	
	}
	if (greedyChoiceCom1 == one){
		comLevel =1;
	}
	else if (greedyChoiceCom1 == two){
		comLevel =2;
	}
	else if (greedyChoiceCom1 == three){
		comLevel =3;
	}
	if (speedMode == low){
		speedCom = 1;
	}
	else if(speedMode == medium){
		speedCom = 2;
	}
	else if(speedMode == high){
		speedCom = 3;
	}
	if (selectPlayerState==pvp){
		battleMode = 1;
		turn = 1;
	}
	else if (selectPlayerState == pvc){
		battleMode = 2;
		turn = 1;
	}
	else if (selectPlayerState == cvc){
		battleMode = 3;
		turn = 4;
	}
	enemyFront = false;
	myCheckers.initBoards(boardSize);
	myCheckers.initCoin();
	std::cout<<endl<<"init coin";
	gameStatus = playing;
	initGame = false;

}
void playerTurn(){
	 if (battleMode == 1){ // multi player
		if(turn==1){
			turn = 2;
		}
		else if (turn==2) { 
						turn = 1;
			 }
	 }
	 else if (battleMode == 2){ // player vs AI
		if(turn==1){
			turn = 3;
		}
		else if (turn==3) {
						turn = 1;
			 }
//
	 }
	 else if (battleMode == 3){ // AI vs AI
				//
		if(turn==3){
			turn = 4;
		}
		else if (turn==4) {
			turn = 3;
			
		 }
	 }
}
void comAIMovement(int *moveTo, bool stillEat){
	switch(comLevel){
	
		case 1: // greedy by side
			/*
			AI pada level satu merupakan Greedy by side. Algoritma ini mengutamakan keberadaan coin checkers agar selalu ada di samping papan
			*/
			if (enemyFront){ // jika harus memakan lawan
				if (!stillEat){ // jika baru pertama kali berhadapan dengan lawan
					// cari koin yang bisa makan di paling depan
					currentCoin = myCheckers.frontKiller(turn);
					cout<<endl<<"coin yang dipilih untuk membunuh= "<<currentCoin;
					
					(*moveTo) = myCheckers.frontPassKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh= "<<(*moveTo);
				}
				else{ // jika harus memakan lawan lagi
					// cari arah makan yang paling di samping papan
					(*moveTo) = myCheckers.frontPassKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh lagi= "<<(*moveTo);
				}
			}
			else{
				currentCoin = myCheckers.sideCoin(turn);
				cout<<endl<<"coin yang dipilih untuk melangkah= "<<currentCoin;
				(*moveTo) = myCheckers.sideMove(currentCoin);
				cout<<endl<<"langkah yang dipilih = "<<(*moveTo);
				if ((*moveTo)==0){
					cout<<"##########################################################################"<<endl<<endl<<"STOP!!!"<<endl<<endl;
				}
				
			}
			// coin = mostSideCoin(); // memilih koin yang prioritas utama berada di paling samping dan masih dapat bergerak ke samping
			// moveTo = mostSideGoal(); // memutuskan arah gerak untuk menuju ke paling samping papan

			break;
	 case 2: //greedy by kiri payeun and kill the most
			// /*
			// AI pada level dua merupakan Greedy yang mengutamakan gerak bidak paling depan untuk ke kiri, sedangkan bila dihadapkan dengan lawan dipilih bidak untuk memakan lawan paling banyak
			// */
			if (enemyFront){ // jika harus memakan lawan
				if (currentCoin==9999){ // jika baru pertama kali berhadapan dengan lawan
					// cari koin yang bisa makan di paling depan
					currentCoin = myCheckers.coinMostKill(turn);
					cout<<endl<<"coin yang dipilih untuk membunuh dari most kill= "<<currentCoin;
					(*moveTo) = myCheckers.moveMostKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh= "<<(*moveTo);
				}
				else{ // jika harus memakan lawan lagi
					// cari arah makan yang paling di samping papan
					(*moveTo) = myCheckers.moveMostKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh lagi= "<<(*moveTo);
				}
			}
			else{
				currentCoin = myCheckers.furthestCoinToMove(turn);
				cout<<endl<<"coin yang dipilih untuk melangkah= "<<currentCoin;
				(*moveTo) = myCheckers.leftMove(currentCoin);
				cout<<endl<<"langkah yang dipilih = "<<(*moveTo);					
			}
			break;
	 case 3: //greedy by kiri payeun almost
			// /*
			// AI pada level tiga merupakan Greedy yang mengutamakan pemilihan koin paling depan untuk bergerak ke kiri, termasuk ketika berhadapan dengan lawan dipilih bidak yang paling depan lalu kiri
			// */
			if (enemyFront){ // jika harus memakan lawan
				if (currentCoin==9999){ // jika baru pertama kali berhadapan dengan lawan
					// cari koin yang bisa makan di paling depan
					currentCoin = myCheckers.furthestCoinToKill(turn);
					cout<<endl<<"coin yang dipilih untuk membunuh= "<<currentCoin;
					(*moveTo) = myCheckers.leftKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh= "<<(*moveTo);
				}
				else{ // jika harus memakan lawan lagi
					// cari arah makan yang paling di samping papan
					(*moveTo) = myCheckers.leftKill(currentCoin);
					cout<<endl<<"langkah yang dipilih untuk membunuh lagi= "<<(*moveTo);
				}
			}
			else{
				currentCoin = myCheckers.furthestCoinToMove(turn);
				cout<<endl<<"coin yang dipilih untuk melangkah= "<<currentCoin;
				(*moveTo) = myCheckers.leftMove(currentCoin);
				cout<<endl<<"langkah yang dipilih = "<<(*moveTo);
				
			}
			
			break;

	}
}
void confirmSave(){
	// int save;
	// cout<<endl<<"save or without save? (1/0) = ";
	// cin>>save;
	// if (save==1){
		// mHistory.SaveLastGame(saveFile, myCheckers.allCoin(), boardSize, battleMode, comLevel, turn, enemyFront);
	// }
	// else{
		// mHistory.SaveLastGame(saveFile, myCheckers.allCoin(), boardSize, battleMode, comLevel, turn, enemyFront);
	// }
}
	void playerMovement(int *moveTo){
		int dir;
		if (enemyFront){ // jika harus memakan lawan
			if (currentCoin==9999){ // jika baru pertama kali berhadapan dengan lawan
				// cari koin yang bisa makan di paling depan
				cout<<endl<<"pilihan coin = ";
				cin>>currentCoin;
				cout<<endl<<"makan coin! Mempass lawan ke (1:kiri atas, 2: kanan atas, 3: kanan bawah, 4: kiri bawah) = ";
				cin>>dir;

			}
			else{ // jika harus memakan lawan lagi
				// cari arah makan yang paling di samping papan
				cout<<endl<<"makan coin lagi! Mempass lawan ke (1:kiri atas, 2: kanan atas, 3: kanan bawah, 4: kiri bawah) = ";
				cin>>dir;
			}
		}
		else{
			cout<<endl<<"pilihan coin = ";
			cin>>currentCoin;
			cout<<endl<<"langkahkan coin ke (1:kiri atas, 2: kanan atas, 3: kanan bawah, 4: kiri bawah) = ";
			cin>>dir;
		}
		if (currentCoin==1234){
			confirmSave();
		}
		(*moveTo) = dir;
				
	}
int getCoinFromMouse(int x, int y){
	int result = 0;
	int posX, posY;
	int startX = (glutGet(GLUT_WINDOW_WIDTH)/1024.0)*275;
	int startY = (glutGet(GLUT_WINDOW_HEIGHT)/768.0)*20;
	// std::cout<<endl<<"startX = "<<startX;
	// std::cout<<endl<<"startY = "<<startY;
	// std::cout<<endl<<"x = "<<x;
	// std::cout<<endl<<"y = "<<y;
	if (boardSize == 8){
		posX = (x-startX)/(91*((glutGet(GLUT_WINDOW_WIDTH)/1024.0)));
		posY = (y-startY)/(91*((glutGet(GLUT_WINDOW_HEIGHT)/768.0)));
	// std::cout<<endl<<"posx = "<<posX;
	// std::cout<<endl<<"posy = "<<posY;
	}
	else{
		posX = (x-startX)/(73*((glutGet(GLUT_WINDOW_WIDTH)/1024.0)));
		posY = (y-startY)/(73*((glutGet(GLUT_WINDOW_HEIGHT)/768.0)));
	}
	if (x<startX){
		posX = 0;
	}
	if (y<startY){
		posY = 0;
	}
	result = myCheckers.getCoinNumberFromArea(posX, posY);
	std::cout<<endl<<posX<<","<<posY;
	std::cout<<endl<<result;
	if (!(((turn ==1) && (result>myCheckers.secondCoinStartIdx)) || ((turn==2) && (result<=myCheckers.secondCoinStartIdx)))){
		result = 0;
	}
	return result;
}
bool currentTurn(char coin){
	bool check = false;
	if ((coin=='b')&&((turn==2) || (turn==3))){ // jika koin black
		check = true;
	}
	else if ((coin=='r')&&((turn==1) || (turn==4))){ // jika koin red
		check = true;
	}
	return check;
}
int* getAreaFromMouse(int x, int y){
	int result[2];
	int posX, posY;
	int startX = (glutGet(GLUT_WINDOW_WIDTH)/1024.0)*275;
	int startY = (glutGet(GLUT_WINDOW_HEIGHT)/768.0)*20;
	// std::cout<<endl<<"startX = "<<startX;
	// std::cout<<endl<<"startY = "<<startY;
	// std::cout<<endl<<"x = "<<x;
	// std::cout<<endl<<"y = "<<y;
	if (boardSize == 8){
		posX = (x-startX)/(91*((glutGet(GLUT_WINDOW_WIDTH)/1024.0)));
		posY = (y-startY)/(91*((glutGet(GLUT_WINDOW_HEIGHT)/768.0)));
	// std::cout<<endl<<"posx = "<<posX;
	// std::cout<<endl<<"posy = "<<posY;
	}
	else{
		posX = (x-startX)/(73*((glutGet(GLUT_WINDOW_WIDTH)/1024.0)));
		posY = (y-startY)/(73*((glutGet(GLUT_WINDOW_HEIGHT)/768.0)));
	}

	if (x<startX){
		result[0] = 0;
	}
	if (y<startY){
		result[1] = 0;
	}
	result[0] = posX;
	result[1] = posY;
	std::cout<<endl<<result;
	return result;
}

// region kerjaan mp
void renderBitmapString(float x, float y, void *font, char *string)
{
	char *c;
	glRasterPos2f(x, y);
	for (c=string; *c != '\0'; c++)
	{
		glutBitmapCharacter(font, *c);
	}
}
// endregion kerjaan mp

void drawStartMenu()
{
	glBindTexture(GL_TEXTURE_2D, backgroundStartMenu_id);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f); // Bottom left of the texture and quad
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f); // Bottom right of the texture and quad
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414); // Top right of the texture and quad
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414); // Top left of the texture and quad
	glEnd();
	//std::cout<<"masuk drawstartmenu"<<endl;
}

void drawBidak()
{
	float deltaX;
	float deltaY;
	float startX ;
	float startY ;
	int ratio;
	if (boardSize==8){
		deltaX = 0.83;
		deltaY = 0.83;
		startY = 2.9;
		startX =  - 1.75;
		ratio =91;
	}
	else{
		deltaX = 0.826;
		deltaY = 0.826;
		startX =  - 2.28;
		startY = 3.73;
		ratio = 73;
	}
	int getX, getY;
	for (int b=1;b<=(myCheckers.coinMaxIdx+1);b++){
		if (myCheckers.getCoin(b).getAlive()==1){
			getX = myCheckers.getCoin(b).getX();
			getY = myCheckers.getCoin(b).getY();
			//std::cout<<endl<<"bidak "<<b<<", x="<<x<<",y="<<y<<endl;
			if (b<=myCheckers.secondCoinStartIdx){ // coin bagian atas atau black
				if (possibleAreaToMove[0][0] == b){ // coin yang diseleksi
					if (myCheckers.getCoin(b).getStatus()==1){

						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, bidak1_pressed_1);
						}
						else{
							glBindTexture(GL_TEXTURE_2D, bidak1_pressed_2);
						}					
					}
					else{
						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, king1_pressed_1);
						}
						else{
							glBindTexture(GL_TEXTURE_2D, king1_pressed_2);
						}
					}
				}
				else{ // coin yang tidak di seleksi
					if (myCheckers.getCoin(b).getStatus()==1){
						if (themeState==classic){
							if ((myCheckers.mustEat(b)) && (turn==2)){
								glBindTexture(GL_TEXTURE_2D, bidak1_eat_1);							
							}
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, bidak1_after_1);								
								}
								else{
									glBindTexture(GL_TEXTURE_2D, bidak1_1);
								}
							}
						}
						else{
							if ((myCheckers.mustEat(b))&&(turn==2)){
								glBindTexture(GL_TEXTURE_2D, bidak1_eat_2);							
							}
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, bidak1_after_2);								
								}
								else{
									glBindTexture(GL_TEXTURE_2D, bidak1_2);
								}
							}
						}
					}
					else{
						if (themeState==classic){
							if ((myCheckers.mustEat(b))&&(turn==2)){
								glBindTexture(GL_TEXTURE_2D, king1_eat_1);							
							}
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, king1_after_1);							
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, king1_1);
								}
							}
						}
						else{
							if ((myCheckers.mustEat(b))&&(turn==2)){
								glBindTexture(GL_TEXTURE_2D, king1_eat_2);							
							}
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, king1_after_2);							
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, king1_2);
								}
							}
						}
					}
				}
			}
			else{ // coin bagian bawah atau red
				if (possibleAreaToMove[0][0]== b){ // coin yang diseleksi
					if (myCheckers.getCoin(b).getStatus()==1){
						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, bidak2_pressed_1);			
						}
						else{
							glBindTexture(GL_TEXTURE_2D, bidak2_pressed_2);			
						}

					}
					else{
						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, king2_pressed_1);			
						}
						else{
							glBindTexture(GL_TEXTURE_2D, king2_pressed_2);			
						}
					
					}

				}
				else{ // coin yang tidak diseleksi
					if (myCheckers.getCoin(b).getStatus()==1){

						if (themeState==classic){
							if ((myCheckers.mustEat(b))&&(turn ==1)){
								glBindTexture(GL_TEXTURE_2D, bidak2_eat_1);							
							}							
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, bidak2_after_1);			
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, bidak2_1);			
								}
							}
						}
						else{
							if ((myCheckers.mustEat(b))&&(turn ==1)){
								glBindTexture(GL_TEXTURE_2D, bidak2_eat_2);
							}							
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, bidak2_after_2);			
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, bidak2_2);
								}
							}
						}
					}
					else{
						if (themeState==classic){
							if ((myCheckers.mustEat(b))&&(turn ==1)){
								glBindTexture(GL_TEXTURE_2D, king2_eat_1);
							}							
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, king2_after_1);			
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, king2_1);			
								}
							}
						}
						else{
							if ((myCheckers.mustEat(b))&&(turn ==1)){
								glBindTexture(GL_TEXTURE_2D, king2_eat_2);
							}							
							else{
								if (b==currentCoin){
									glBindTexture(GL_TEXTURE_2D, king2_after_2);			
																	
								}
								else{
									glBindTexture(GL_TEXTURE_2D, king2_2);			
								}
							}
						}
					
					}
				}
			}
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414f + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768)); //draw images dimulai dari kiri bawah
				glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768));   // dilanjutkan ke kanan bawah
				glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));     // setelah itu ke kanan atas
				glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));    // dan berakhir di kiri atas

				// glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 - 0.91 + (((x + (x % 2)) / 2) * 1.66) - (((x + 1) % 2) * 1.66)) * widthRatio(91, 1024), (-0.414f + 2.9 - (y * 0.83)) * heightRatio(91, 768)); //draw images dimulai dari kiri bawah
				// glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 - 0.91 + (((x + (x % 2)) / 2) * 1.66) - (((x + 1) % 2) * 1.66)) * widthRatio(91, 1024), (-0.414f + 2.9 - (y * 0.83)) * heightRatio(91, 768));   // dilanjutkan ke kanan bawah
				// glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 - 0.91 + (((x + (x % 2)) / 2) * 1.66) - (((x + 1) % 2) * 1.66)) * widthRatio(91, 1024), (0.414 + 2.9 - (y * 0.83)) * heightRatio(91, 768));     // setelah itu ke kanan atas
				// glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 - 0.91 + (((x + (x % 2)) / 2) * 1.66) - (((x + 1) % 2) * 1.66)) * widthRatio(91, 1024), (0.414 + 2.9 - (y * 0.83)) * heightRatio(91, 768));    // dan berakhir di kiri atas
			glEnd();
		}
	
	}
}

void drawOptions()
{
	// region kerjaan mp
	renderBitmapString(-0.20, 0.29,GLUT_BITMAP_TIMES_ROMAN_24, (char*)player1name.c_str());
	renderBitmapString(-0.20, 0.21,GLUT_BITMAP_TIMES_ROMAN_24, (char*)player2name.c_str());

	float x = 0;
	float y = 0;
	int xratio = 142;
	int yratio = 93;
	if (selectPlayerState == pvp)
	{
		glBindTexture(GL_TEXTURE_2D, pvp_id);
		x = -1.2;
		y = 0.90;
	}
	if (selectPlayerState == pvc)
	{
		glBindTexture(GL_TEXTURE_2D, pvc_id);
		x = -0.10;
		y = 0.90;
	}
	if (selectPlayerState == cvc)
	{
		glBindTexture(GL_TEXTURE_2D, cvc_id);
		x = 1.04;
		y = 0.90;
	}

	//- 0.414 + x, 0.414 - y
//231 , 236   0.0934, 0.0954
//422, 238   0.1706, 0.1272
//618, 229   0.2498, 0.1234

//-0.3206, 0.3186
//-0.2434, 0.2868
//-0.1642, 0.2906

//0.0659, 0.5768
	// draw GameMode
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
		glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
		glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
		glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
	glEnd();
	// ngasal
	if (selectPlayerState == cvc)
	{
		if (greedyChoiceCom1 == one)
		{
			glBindTexture(GL_TEXTURE_2D, bysave_id);
			x = -1.21;
			y = 0.05;
		}
		else if (greedyChoiceCom1 == two)
		{
			glBindTexture(GL_TEXTURE_2D, byaggressive_id);
			x = -0.1;
			y = 0.1;
		}
		else if (greedyChoiceCom1 == three)
		{
			glBindTexture(GL_TEXTURE_2D, hybrid_id);
			x = 0.98;
			y = 0.08;
		}

        glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();

		if (greedyChoiceCom2 == one)
		{
			glBindTexture(GL_TEXTURE_2D, bysave_id);
			x = -1.25;
			y = -0.62;
		}
		else if (greedyChoiceCom2 == two)
		{
			glBindTexture(GL_TEXTURE_2D, byaggressive_id);
			x = -0.15;
			y = -0.58;
		}
		else if (greedyChoiceCom2 == three)
		{
			glBindTexture(GL_TEXTURE_2D, hybrid_id);
			x = 0.95;
			y = -0.6;
		}

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();

		if (speedMode == low)
		{
			glBindTexture(GL_TEXTURE_2D, low_id);
			x = -1.2;
			y = -1.33;
		}
		else if (speedMode == medium)
		{
			glBindTexture(GL_TEXTURE_2D, medium_id);
			x = -0.10;
			y = -1.28;
		}
		else if (speedMode == high)
		{
			glBindTexture(GL_TEXTURE_2D, high_id);
			x = 1.03;
			y = -1.25;
		}

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();

		if (boardSizeMode == eight)
		{
			glBindTexture(GL_TEXTURE_2D, eight_id);
			x = -1.22;
			y = -1.95;
		}
		if (boardSizeMode == ten)
		{
			glBindTexture(GL_TEXTURE_2D, ten_id);
			x = -0.13;
			y = -1.97;
		}

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();
	}
	else
	{
		if (speedMode == low)
		{
			glBindTexture(GL_TEXTURE_2D, low_id);
			x = -1.2;
			y = -0.1;
		}
		if (speedMode == medium)
		{
			glBindTexture(GL_TEXTURE_2D, medium_id);
			x = -0.10;
			y = -0.1;
		}
		if (speedMode == high)
		{
			glBindTexture(GL_TEXTURE_2D, high_id);
			x = 1.03;
			y = -0.1;
		}

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();

		// draw radio button for choosing board size
		if (boardSizeMode == eight)
		{
			glBindTexture(GL_TEXTURE_2D, eight_id);
			x = -1.20;
			y = -1.04;
		}
		if (boardSizeMode == ten)
		{
			glBindTexture(GL_TEXTURE_2D, ten_id);
			x = -0.1;
			y = -1.04;
		}

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (-0.414 + y) * heightRatio(yratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + x) * widthRatio(xratio, 1024), (0.414 + y) * heightRatio(yratio, 768));    // dan berakhir di kiri atas
		glEnd();
	}
	// endregion kerjaan mp

	if (selectPlayerState == cvc)
	{
		glBindTexture(GL_TEXTURE_2D, bg_options_1_cvc);
	}
	else
	{
		glBindTexture(GL_TEXTURE_2D, bg_options_1);
	}

	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f);	// Bottom left of the texture and quad
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f); // Bottom right of the texture and quad
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414); // Top right of the texture and quad
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414); // Top left of the texture and quad
	glEnd();
}

void drawHelp()
{
	if (themeState==classic){
		glBindTexture(GL_TEXTURE_2D, bg_help_1);
	}
	else{
		glBindTexture(GL_TEXTURE_2D, bg_help_2);
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f);	// Bottom left of the texture and quad
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f); // Bottom right of the texture and quad
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414); // Top right of the texture and quad
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414); // Top left of the texture and quad
	glEnd();
}

void drawCredits()
{
	if (themeState==classic){
		glBindTexture(GL_TEXTURE_2D, bg_credits_1);
	}
	else{
		glBindTexture(GL_TEXTURE_2D, bg_credits_2);
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f); // Bottom left of the texture and quad
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f); // Bottom right of the texture and quad
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414); // Top right of the texture and quad
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414); // Top left of the texture and quad
	glEnd();
}

void drawGamePlay()
{
	// mengikat texture
	drawScore();

	// draw giliran
	drawTurn();
	
	// draw papan kemenangan
	drawWin();
	
	//draw ableMove
	drawBoardsFeatures();

	// draw bidak
	drawBidak();

	// draw board
	drawBoards();
	//std::cout<<"masuk drawgameplay"<<endl;
}
void drawBoards(){

	if (themeState==classic){
		glBindTexture(GL_TEXTURE_2D, bg_gameplay_1);
	}
	else{
		glBindTexture(GL_TEXTURE_2D, bg_gameplay_2);
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f); //draw images dimulai dari kiri bawah
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f);   // dilanjutkan ke kanan bawah
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414);     // setelah itu ke kanan atas
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414);    // dan berakhir di kiri atas
	glEnd();

	//glBindTexture(GL_TEXTURE_2D, backgroundGamePlay_id);
	//glBindTexture(GL_TEXTURE_2D, papan_id);
	//glBindTexture(GL_TEXTURE_2D, papanselected_id);
	//glBindTexture(GL_TEXTURE_2D, arah_id);
	//glBindTexture(GL_TEXTURE_2D, posibilitas_id);

}
void drawScore(){
	char score1[2], score2[2];
	itoa((myCheckers.coinMaxIdx + 1)/2 - myCheckers.remainingCoin(2), score1, 10);
	itoa((myCheckers.coinMaxIdx + 1)/2 - myCheckers.remainingCoin(1), score2, 10);
	// cout<<endl<<"score 1 = "<<score1;
	// cout<<endl<<"score 2 = "<<score2;
 	renderBitmapString(-0.290, 0.135, GLUT_BITMAP_TIMES_ROMAN_24, score1);//(const char*)history.GetPlayer(2).getTime());
 	renderBitmapString(-0.290, 0.220, GLUT_BITMAP_TIMES_ROMAN_24, score2);//(const char*)history.GetPlayer(2).getTime());

}
void drawBoardsFeatures(){
	float deltaX;
	float deltaY;
	float startX ;
	float startY ;
	int ratio;
	int getX, getY;
	bool mustEat;
	if (boardSize==8){
		deltaX = 0.83;
		deltaY = 0.83;
		startY = 2.9;
		startX =  - 1.75;
		ratio =91;
	}
	else{
		deltaX = 0.826;
		deltaY = 0.826;
		startX =  - 2.28;
		startY = 3.73;
		ratio = 73;
	}
		//std::cout<<endl<<"Possible nih = "<<possibleAreaToMove[0][0];
		if (possibleAreaToMove[0][0]!=0){
			for (int a=1;a<=4;a++){
				mustEat = false;
				getX = myCheckers.getCoin(possibleAreaToMove[0][0]).getX();
				getY = myCheckers.getCoin(possibleAreaToMove[0][0]).getY();
				if (possibleAreaToMove[0][a]==1){
					if (a==1){
						getX-=1;
						getY-=1;
					}
					else if (a==2){
						getX+=1;
						getY-=1;
					}
					else if (a==3){
						getX+=1;
						getY+=1;
					}
					else if (a==4){
						getX-=1;
						getY+=1;
					}
				}
				else if (possibleAreaToMove[0][a]==2){
					mustEat = true;
					if (a==1){
						getX-=2;
						getY-=2;															
					}
					else if (a==2){
						getX+=2;
						getY-=2;										
					}
					else if (a==3){
						getX+=2;
						getY+=2;										
					}
					else if (a==4){
						getX-=2;
						getY+=2;					
					}
				}
				
				
				if (possibleAreaToMove[0][a]!=0){		 // menggambar kemungkinan langkah yang dapat dipilih		
				// std::cout<<endl<<"masuk posible"<<getX<<getY;
					if (mustEat){
						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, posibilitas_eat_1);						
						}
						else{
							glBindTexture(GL_TEXTURE_2D, posibilitas_eat_2);						
						}
					}
					else{
						if (themeState==classic){
							glBindTexture(GL_TEXTURE_2D, posibilitas_1);						
						}
						else{
							glBindTexture(GL_TEXTURE_2D, posibilitas_2);						
						}
					}
					
					glBegin(GL_QUADS);
						glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414f + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768)); //draw images dimulai dari kiri bawah
						glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768));   // dilanjutkan ke kanan bawah
						glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));     // setelah itu ke kanan atas
						glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));    // dan berakhir di kiri atas
					glEnd();
				}
				
				
			}
		}
		
		// menggambar jejak langkah
		if (currentCoin!=0){
				getX = lastMove[0];
				getY = lastMove[1];
				
				if (themeState==classic){
					glBindTexture(GL_TEXTURE_2D, papanafter_1);						
				}
				else{
					glBindTexture(GL_TEXTURE_2D, papanafter_2);						
				}
				glBegin(GL_QUADS);
					glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414f + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768)); //draw images dimulai dari kiri bawah
					glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (-0.414f +startY - (deltaY*getY)) * heightRatio(ratio, 768));   // dilanjutkan ke kanan bawah
					glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));     // setelah itu ke kanan atas
					glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + startX + (deltaX*getX)) * widthRatio(ratio, 1024), (0.414 +startY - (deltaY*getY)) * heightRatio(ratio, 768));    // dan berakhir di kiri atas
				glEnd();
			
			
		}
}

// region kerjaan mp
void drawHighScore()
{
    int i = 0;
	char coinleft[10][10], time[10][10];
	char *buf ;
	for (i = 0; i < 10; i++)
	{
		itoa(mHistory.GetPlayer(i).getCoinLeft(), coinleft[i], 10);
		itoa(mHistory.GetPlayer(i).getTime(), time[i], 10);
//		mHistory.setName(i, "ano");
	}
//	mHistory.initHighScore(8);

	// draw header
	renderBitmapString(-0.3, 0.05 * 11 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "Nama Pemain");//(const char*)history.GetPlayer(2).getTime());
	renderBitmapString(0, 0.05 * 11 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "Koin Sisa");//(const char*)history.GetPlayer(3).getTime());
	renderBitmapString(0.3, 0.05 * 11 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "Waktu");//(const char*)history.GetPlayer(4).getTime());
	// for (i = 0; i < 10; ++i)
	// {
		// cout<<endl<<"nama="<<mHistory.GetPlayer(i).getName();
		// cout<<endl<<"coin="<<mHistory.GetPlayer(i).getCoinLeft();
		// cout<<endl<<"time="<<mHistory.GetPlayer(i).getTime();
	// }
	for (int i=10;i>0;i--){
		// cout<<endl<<"nama asli "<<i<<" = "<<mHistory.GetPlayer(10-i).getName();
		buf = (char*)malloc( sizeof( char ) *(mHistory.GetPlayer(10-i).getName().length() +1) );
		strcpy( buf, mHistory.GetPlayer(10-i).getName().c_str() );	
		// cout<<endl<<"buf = "<<buf;
		renderBitmapString(-0.3, 0.05 * i - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, buf);
		renderBitmapString(0, 0.05 * i - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[10-i]);
		renderBitmapString(0.3, 0.05 * i - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[10-i]);
		delete []buf;

	}
	// renderBitmapString(-0.3, 0.05 * 10 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "WWWWWWWWWWWWWWWWWWWW");
	// renderBitmapString(-0.3, 0.05 * 9 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes2");//(const char*)history.GetPlayer(1).getTime());
	// renderBitmapString(-0.3, 0.05 * 8 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes3");//(const char*)history.GetPlayer(2).getTime());
	// renderBitmapString(-0.3, 0.05 * 7 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes4");//(const char*)history.GetPlayer(3).getTime());
	// renderBitmapString(-0.3, 0.05 * 6 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes5");//(const char*)history.GetPlayer(4).getTime());
	// renderBitmapString(-0.3, 0.05 * 5 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes6");//(const char*)history.GetPlayer(5).getTime());
	// renderBitmapString(-0.3, 0.05 * 4 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes7");//(const char*)history.GetPlayer(6).getTime());
	// renderBitmapString(-0.3, 0.05 * 3 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes8");//(const char*)history.GetPlayer(7).getTime());
	// renderBitmapString(-0.3, 0.05 * 2 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes9");//(const char*)history.GetPlayer(8).getTime());
	// renderBitmapString(-0.3, 0.05 * 1 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, "tes10");//(const char*)history.GetPlayer(9).getTime());

	// renderBitmapString(0, 0.05 * 10 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[1]);
	// renderBitmapString(0, 0.05 * 9 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[2]);//(const char*)history.GetPlayer(1).getTime());
	// renderBitmapString(0, 0.05 * 8 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[3]);//(const char*)history.GetPlayer(2).getTime());
	// renderBitmapString(0, 0.05 * 7 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[4]);//(const char*)history.GetPlayer(3).getTime());
	// renderBitmapString(0, 0.05 * 6 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[5]);//(const char*)history.GetPlayer(4).getTime());
	// renderBitmapString(0, 0.05 * 5 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[6]);//(const char*)history.GetPlayer(5).getTime());
	// renderBitmapString(0, 0.05 * 4 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[7]);//(const char*)history.GetPlayer(6).getTime());
	// renderBitmapString(0, 0.05 * 3 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[8]);//(const char*)history.GetPlayer(7).getTime());
	// renderBitmapString(0, 0.05 * 2 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[9]);//(const char*)history.GetPlayer(8).getTime());
	// renderBitmapString(0, 0.05 * 1 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, coinleft[10]);//(const char*)history.GetPlayer(9).getTime());

	// renderBitmapString(0.3, 0.05 * 10 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[1]);
	// renderBitmapString(0.3, 0.05 * 9 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[2]);//(const char*)history.GetPlayer(1).getTime());
	// renderBitmapString(0.3, 0.05 * 8 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[3]);//(const char*)history.GetPlayer(2).getTime());
	// renderBitmapString(0.3, 0.05 * 7 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[4]);//(const char*)history.GetPlayer(3).getTime());
	// renderBitmapString(0.3, 0.05 * 6 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[5]);//(const char*)history.GetPlayer(4).getTime());
	// renderBitmapString(0.3, 0.05 * 5 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[6]);//(const char*)history.GetPlayer(5).getTime());
	// renderBitmapString(0.3, 0.05 * 4 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[7]);//(const char*)history.GetPlayer(6).getTime());
	// renderBitmapString(0.3, 0.05 * 3 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[8]);//(const char*)history.GetPlayer(7).getTime());
	// renderBitmapString(0.3, 0.05 * 2 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[9]);//(const char*)history.GetPlayer(8).getTime());
	// renderBitmapString(0.3, 0.05 * 1 - 0.3, GLUT_BITMAP_TIMES_ROMAN_24, time[10]);//(const char*)history.GetPlayer(9).getTime());

	// cout<<"masuk highscore"<<endl;
	glBindTexture(GL_TEXTURE_2D, bg_highscore);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-0.414f, -0.414f); // Bottom left of the texture and quad
		glTexCoord2f(1.0f, 0.0f); glVertex2f(0.414, -0.414f); // Bottom right of the texture and quad
		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.414, 0.414); // Top right of the texture and quad
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-0.414, 0.414); // Top left of the texture and quad
	glEnd();
}
// endregion kerjaan mp

void draw()
{   // Clear Color and Depth Buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// load ulang image-image yang ada
	
	loadContent();
	
	// Reset transformations
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	glTranslatef(0, 0, -1); // translasi ke sumbu-Z negatif
	if (gameState == startmenu)
	{
		  drawStartMenu();
	}
	else if (gameState == gameplay)
	{
		if (initGame){
		  drawGamePlay();
		 }
	}
	else if (gameState == options)
	{
		drawOptions();
	}
	else if (gameState == help)
	{
		drawHelp();
	}
	else if (gameState == credits)
	{
		drawCredits();
	}
	else if (gameState == highscore)
	{
    	// cout<<"highscore?"<<endl;
		drawHighScore();
	}

	glutSwapBuffers();
}
void drawTurn(){
	int posX =-3;
	int posY =0;
	int ratio =150;
	if ((gameStatus==black_win)|| (gameStatus == red_win)){
		if (gameStatus==black_win){
			glBindTexture(GL_TEXTURE_2D, win_black);						
		}
		else if (gameStatus==red_win){
			glBindTexture(GL_TEXTURE_2D, win_red);						
		
		}
		
	}
	else if (gameStatus == playing){
		if (currentTurn('r')){
			glBindTexture(GL_TEXTURE_2D, turn_red);
			ratio = 100;
		}
		else{
			glBindTexture(GL_TEXTURE_2D, turn_black);
			ratio = 100;
		}
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414f + posX ) * widthRatio(ratio, 1024), (-0.414f +posY ) * heightRatio(ratio, 768)); //draw images dimulai dari kiri bawah
		glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + posX ) * widthRatio(ratio, 1024), (-0.414f +posY ) * heightRatio(ratio, 768));   // dilanjutkan ke kanan bawah
		glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + posX) * widthRatio(ratio, 1024), (0.414 +posY ) * heightRatio(ratio, 768));     // setelah itu ke kanan atas
		glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + posX ) * widthRatio(ratio, 1024), (0.414 +posY) * heightRatio(ratio, 768));    // dan berakhir di kiri atas
	glEnd();

}
void drawWin(){
	if ((gameStatus==black_win)|| (gameStatus == red_win)){
		int posX =-2;
		int posY =0;
		int ratio =150;
		if (gameStatus==black_win){
			glBindTexture(GL_TEXTURE_2D, win_black);						
		}
		else if (gameStatus==red_win){
			glBindTexture(GL_TEXTURE_2D, win_red);						
		
		}
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f((-0.414f + posX ) * widthRatio(ratio, 1024), (-0.414f +posY ) * heightRatio(ratio, 768)); //draw images dimulai dari kiri bawah
			glTexCoord2f(1.0f, 0.0f); glVertex2f((0.414 + posX ) * widthRatio(ratio, 1024), (-0.414f +posY ) * heightRatio(ratio, 768));   // dilanjutkan ke kanan bawah
			glTexCoord2f(1.0f, 1.0f); glVertex2f((0.414 + posX) * widthRatio(ratio, 1024), (0.414 +posY ) * heightRatio(ratio, 768));     // setelah itu ke kanan atas
			glTexCoord2f(0.0f, 1.0f); glVertex2f((-0.414 + posX ) * widthRatio(ratio, 1024), (0.414 +posY) * heightRatio(ratio, 768));    // dan berakhir di kiri atas
		glEnd();
	}

}
void initBitmap(){
		backgroundStartMenu_id = loadBMP("images/startmenu.bmp");

		bg_options_1 = loadBMP("images/klasik/options.bmp");
		bg_options_1_cvc = loadBMP("images/klasik/options_cvc.bmp");
		// cout<<"load1?"<<endl;
		bg_help_1 = loadBMP("images/klasik/help.bmp");
		// cout<<"load2?"<<endl;
		bg_credits_1 = loadBMP("images/klasik/credits.bmp");

		pvp_id = loadBMP("images/klasik/orang-orang.bmp");
		pvc_id = loadBMP("images/klasik/orang-comp.bmp");
		cvc_id = loadBMP("images/klasik/comp-comp.bmp");

		low_id = loadBMP("images/klasik/lambat.bmp");
		medium_id = loadBMP("images/klasik/sedang.bmp");
		high_id = loadBMP("images/klasik/cepat.bmp");

		byaggressive_id = loadBMP("images/klasik/by aggressive.bmp");
		bysave_id = loadBMP("images/klasik/by save.bmp");
		hybrid_id = loadBMP("images/klasik/hybrid.bmp");

		eight_id = loadBMP("images/klasik/8x8.bmp");
		ten_id = loadBMP("images/klasik/10x10.bmp");

		// load content for gameplay
		turn_red = loadBMP("images/klasik/bidakmerahturn.bmp");
		turn_black = loadBMP("images/klasik/bidakhitamturn.bmp");

		// papan kemenangan
		win_black = loadBMP("images/klasik/P2menang.bmp");
		win_red = loadBMP("images/klasik/P1menang.bmp");

		papanafter_1 = loadBMP("images/klasik/papan_klasik_selected.bmp");
		bidak1_after_1 = loadBMP("images/klasik/bidak1_after.bmp");
		bidak2_after_1 = loadBMP("images/klasik/bidak2_after.bmp");
		king1_after_1 = loadBMP("images/klasik/bidak1_raja_after.bmp");
		king2_after_1 = loadBMP("images/klasik/bidak2_raja_after.bmp");
		// cout<<"load4?"<<endl;
		posibilitas_1 = loadBMP("images/klasik/possibilities.bmp");
		posibilitas_eat_1 = loadBMP("images/klasik/papan_eat.bmp");
		// cout<<"load5?"<<endl;
		bidak1_1 = loadBMP("images/klasik/bidak1.bmp");
		// cout<<"load6?"<<endl;
		bidak2_1 = loadBMP("images/klasik/bidak2.bmp");
		bidak1_eat_1 = loadBMP("images/klasik/bidak1_eat.bmp");
		bidak2_eat_1 = loadBMP("images/klasik/bidak2_eat.bmp");
		// cout<<"load7?"<<endl;
		// bg_gameplay_1 = loadBMP("images/klasik/gameplay.bmp");
		// bg_gameplay10_1 = loadBMP("images/klasik/gameplay_10.bmp");
		bg_highscore = loadBMP("images/klasik/highscore_board.bmp");
		// cout<<"load6?"<<endl;
		bidak1_pressed_1 = loadBMP("images/klasik/bidak1_pressed.bmp");
		bidak2_pressed_1 = loadBMP("images/klasik/bidak2_pressed.bmp");
		king1_1 = loadBMP("images/klasik/bidak1_raja.bmp");
		king1_eat_1 = loadBMP("images/klasik/bidak1_raja_eat.bmp");
		king2_eat_1 = loadBMP("images/klasik/bidak2_raja_eat.bmp");
		king2_1= loadBMP("images/klasik/bidak2_raja.bmp");
		king1_pressed_1 = loadBMP("images/klasik/bidak1_raja_pressed.bmp");
		king2_pressed_1 = loadBMP("images/klasik/bidak2_raja_pressed.bmp");

		bg_options_2 = loadBMP("images/unyu/options.bmp");
		bg_help_2 = loadBMP("images/unyu/help.bmp");
		bg_credits_2 = loadBMP("images/unyu/credits.bmp");
		papan_2 = loadBMP("images/unyu/boardunyu.bmp");
		// cout<<"image papan keload?"<<endl;
		papanafter_2 = loadBMP("images/unyu/board_unyu_selected.bmp");
		posibilitas_2 = loadBMP("images/unyu/possibilities.bmp");
		bidak1_2 = loadBMP("images/unyu/bidak1.bmp");
		bidak2_2 = loadBMP("images/unyu/bidak2.bmp");
		// bg_gameplay_2 = loadBMP("images/unyu/gameplay.bmp");

}
void initregister()
{
	int gameWidth = 1024;
	int gameHeight = 768;

	// register callbacks
	glutDisplayFunc(draw);
	glutIdleFunc(updateGamePlay);
	glutReshapeWindow(gameWidth, gameHeight);

	//glutIgnoreKeyRepeat(0);
	glutKeyboardFunc(keyPressed);
	glutMouseFunc(mouseButton);
	//glutMotionFunc(mouseMove);

	// OpenGL init
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
}

int main(int argc, char** argv)
{
	// init state
	gameState = startmenu;
	themeState = classic;
	statusFile = "stat.dat";
	gameFile = "lastGame.dat";
	scoreFile = "score.dat";
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
// backgroundStartMenu_id = loadBMP("images/startmenu.bmp");
	glutCreateWindow("Checkers");
	glutPositionWindow((glutGet (GLUT_SCREEN_WIDTH) - 1024) / 2, (glutGet (GLUT_SCREEN_HEIGHT) - 768 + 24)/2); // membuat posisi windows jadi "centered"
	initBitmap();
	mHistory.initPlayer(scoreFile);
	initialize();
	initregister();
	//cout<<gameState<<endl;
	PlaySound("Data/Freeze.wav", NULL, SND_ASYNC);
	glutMainLoop();
	//system("pause");
	//history.printcmd();
	//system("pause");
	return 0;
}
